package com.durian.base.rxhttp.parse

import com.durian.base.rxhttp.CallCancelFactory
import okhttp3.Response
import java.io.IOException

/**
 * 说明：SuspendParser
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2021/10/20 10:24 下午
 * <p/>
 * 版本：version 1.0
 */
abstract class SuspendParser<T> : Parser<T> {

    var cancelTag = ""

    override fun onParse(response: Response): T {
        throw UnsupportedOperationException("Should be call onSuspendParse fun")
    }

    @Throws(IOException::class)
    abstract suspend fun onSuspendParse(response: Response): T

    fun removeCall(){
        if (cancelTag.isNotEmpty()){
            CallCancelFactory.removeCall(cancelTag)
        }
    }
}